import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2022-11-10
 * Time: 20:50
 */

public class Demo1 {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream("e:/hade/hello.txt");
            //尝试一个字节一个字节的读
            while (true){
                int b = inputStream.read();
                if (b == -1){
                    break;
                }
                System.out.println(b);
            }
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            inputStream.close();
        }
    }


    public static void main1(String[] args) {
        //创建对象的同时 也是在打开文件
        try(InputStream inputStream = new FileInputStream("d:/hade/demo1.txt")){
            //一次读若干个字节
            while (true){
                //循环的去读 要用一个空的字节数组来接收
                byte[] buffer = new byte[1024];
                int len = inputStream.read(buffer);
                if (len == -1){
                    //如果读到的了-1说明是读完了
                    //如果返回 -1
                    break;
                }
                for (int i = 0; i < len; i++) {
                    System.out.println(buffer[i]+ " ");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
